package com.aldobucchi.x.flash.geom
{
	import flash.display.DisplayObject;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class RectangleUtil
	{


		public static function getSmallestScaleToFitAIntoB( rectA:Rectangle, rectB:Rectangle ):Number
		{
			
			var wS:Number = rectB.width 	/ rectA.width;															
			var hS:Number = rectB.height 	/ rectA.height;
			
			return ( wS < hS ? wS : hS );					
		
		}
		
		
		
		public static function applyToDisplayObject( rect:Rectangle, dobj:DisplayObject ):void
		{
			dobj.x 			= rect.x;
			dobj.y 			= rect.y;
			dobj.width 		= rect.width;
			dobj.height 	= rect.height;
		}
		
		
		
		
		/**
		 * 
		 * These can be replaced by only one function
		 * 
		 * @param topLeft
		 * @param bottomRight
		 * @return 
		 * 
		 */		
		public static function fromDiagonals1( topLeft:Point, bottomRight:Point ):Rectangle
		{
			var diff:Point = topLeft.subtract( bottomRight );
			var w:Number = Math.abs( diff.x );
			var h:Number = Math.abs( diff.y );			
			return new Rectangle( topLeft.x, topLeft.y, w, h );	
		}
		


		public static function fromDiagonals2( bottomLeft:Point, topRight:Point ):Rectangle
		{
			var diff:Point = bottomLeft.subtract( topRight );
			var w:Number = Math.abs( diff.x );
			var h:Number = Math.abs( diff.y );			
			var topLeft:Point = new Point( bottomLeft.x, bottomLeft.y - h );
			return new Rectangle( topLeft.x, topLeft.y, w, h );			
		}		
		
		
	}

}